#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
#define ll long long
struct node{
    int d;
    int v;
    int a;
    int st;
    int fi;
}car[maxn];
int cmp1(node x,node y){
    return x.st<y.st;
}
int cmp2(node x,node y){
    return x.fi<y.fi;
}
int n;
int T;

int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d",&T);
    while(T--){
        int n,m,L,V;
        int p[maxn];
        int l[maxn]={0};
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&car[i].d,&car[i].v,&car[i].a);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
            l[p[i]]=1;
        }
        int k=1;
        for(int i=1;i<=L;i++){
            if(l[i]){
                k++;
            }
            l[i]=k;
        }
        for(int i=1;i<=n;i++){
            if(car[i].v<=V&&car[i].a<=0){
                car[i].st=L+1;
                car[i].fi=L+2;
            }else if(car[i].v>V&&car[i].a>=0){
                car[i].st=p[l[car[i].d]];
                car[i].fi=p[l[L]-1];
            }else{
                if(car[i].v<=V){
                    int k=(V*V-car[i].v*car[i].v)/(2*car[i].a)+1;
                    car[i].st=p[l[car[i].d+k]-1];
                    car[i].fi=p[l[L]-1];
                }else{
                    int k=(V*V-car[i].v*car[i].v)/(2*car[i].a);
                    car[i].st=p[l[car[i].d]-1];
                    car[i].fi=p[l[car[i].d+k]-1];
                }
            }
        }
        int ans1=0;
        int ans2=0;
        for(int i=1;i<=n;i++){
            if(car[i].st==car[i].fi)continue;
            ans1++;
        }
        sort(car+1,car+n+1,cmp1);
        sort(car+1,car+n+1,cmp2);
        int to=car[1].fi;
        for(int i=2;i<=n;i++){
            if(car[i].st>=to){
                to=car[i].fi;
                ans2++;
            }
        }
        ans2=m-ans2;
        cout<<ans1<<" "<<ans2<<endl;
    }




    return 0;
}
